package com.df.tank;

import com.df.tank.strategy.DoubleFireStrategy;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Random;

/**
 * 奖励类  坦克获取奖励展现不同功能
 */
public class Award {
    private int x;
    private int y;
    private BufferedImage image = ImageMgr.award;
    private Random random = new Random();
    private Rectangle rectangle = new Rectangle();
    private TankFrame tankFrame=null;

    public Award(TankFrame tankFrame) {
        this.tankFrame = tankFrame;
        this.x = random.nextInt(TankFrame.WIDTH);
        this.y = random.nextInt(TankFrame.HEIGHT);
        rectangle.x = this.x;
        rectangle.y = this.y;
        rectangle.width = image.getWidth();
        rectangle.height = image.getHeight();
    }
    public void paint(Graphics g) {
        //长方形
//        g.fillRect(x, y, 50, 50);
        g.drawImage(image, x, y, null);
    }

    public void getAward(Tank tank) {
        if (tank.getGroup() == Group.GOOD && tank.rect.intersects(this.rectangle)) {
            this.tankFrame.award = null;
            tank.setFireStrategy(DoubleFireStrategy.getInstance());
        }
    }
}
